<?php 
header("content-type:text/html;charset=utf8");
include_once('../07c/PHPExcel-1.8/Classes/PHPExcel.php');

$objPHPExcel = new PHPExcel();

// Add some data
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', 'name')
            ->setCellValue('B1', 'age')
            ->setCellValue('C1', 'money');

$pdo = new PDO("mysql:host=127.0.0.1;dbname=goods;charset=utf8",'root','root');

$data = $pdo->query("SELECT * FROM import")->fetchAll(PDO::FETCH_ASSOC);

$i = 2;
foreach ($data as $key => $value) {
	$objPHPExcel->getActiveSheet()
            ->setCellValue('A'.$i, $value['name'])
            ->setCellValue('B'.$i, $value['age'])
            ->setCellValue('C'.$i, $value['money']);
     $i++;
}

// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="01simple.xlsx"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
 ?>